using UnityEngine;

public class Attack10 : MonoBehaviour
{
	public GameObject effect;

	private Light mainlight;

	private float defaultLightIntensity = 1f;

	private int touchIndex;

	private Vector2 touchStart;

	private Vector2 touchEnd;

	private ParticleSystem chargeParticles;

	private SphereCollider exploderCollider;

	private void Start()
	{
		exploderCollider = base.transform.Find("Exploder").GetComponent<SphereCollider>();
		StateManager.specialAttack = true;
		effect.SetActive(value: false);
		chargeParticles = effect.transform.Find("ChargeParticles").GetComponent<ParticleSystem>();
		base.transform.parent = GameObject.FindGameObjectWithTag("Player").transform;
		base.transform.localPosition = new Vector3(0f, 1f, 0f);
		mainlight = GameObject.Find("Directional light").GetComponent<Light>();
		defaultLightIntensity = mainlight.intensity;
	}

	private void Update()
	{
		if ((bool)effect && effect.active)
		{
			return;
		}
		int touchCount = UnityEngine.Input.touchCount;
		for (int i = 0; i < touchCount; i++)
		{
			Touch touch = UnityEngine.Input.GetTouch(i);
			if (touch.phase == TouchPhase.Began)
			{
				touchStart = touch.position;
				touchEnd = touchStart;
				touchIndex = i;
			}
			else if (i == touchIndex)
			{
				touchEnd = touch.position;
			}
			if (i == touchIndex && touch.phase == TouchPhase.Ended)
			{
				if (!(touchEnd.x / touchStart.x > 0.89f) || !(touchEnd.x / touchStart.x < 1.11f) || !(touchEnd.y / touchStart.y > 0.89f) || !(touchEnd.y / touchStart.y < 1.11f))
				{
					break;
				}
				StartAttack();
			}
		}
	}

	private void StartAttack()
	{
		StateManager.specialEnergy = Mathf.Clamp(StateManager.specialEnergy - 100f, 0f, 100f);
		GetComponent<AudioSource>().Play();
		StateManager.heightLimit = 4;
		if ((bool)effect)
		{
			effect.SetActiveRecursively(state: true);
			Rect cameraRect = Camera.main.rect;
			LeanTween.value(chargeParticles.gameObject, -0.6f, 0.1f, 2f).setOnUpdate(delegate(float val)
			{
				chargeParticles.startSpeed = val;
				float num = Mathf.PerlinNoise(20f * Time.time, 20f * Time.time);
				cameraRect.width = 1f - num * 0.015f;
				cameraRect.height = 1f - num * 0.015f;
				cameraRect.x = 0.015f - num * 0.015f;
				cameraRect.y = 0.015f - num * 0.015f;
				Camera.main.rect = cameraRect;
			}).setEase(LeanTweenType.easeInExpo);
			LeanTween.value(Camera.main.gameObject, 0f, 1f, 1f).setOnUpdate(delegate(float val)
			{
				cameraRect.width = Mathf.Clamp(cameraRect.width + val, 0f, 1f);
				cameraRect.height = Mathf.Clamp(cameraRect.height + val, 0f, 1f);
				cameraRect.x = Mathf.Clamp(cameraRect.x - val, 0f, 1f);
				cameraRect.y = Mathf.Clamp(cameraRect.y - val, 0f, 1f);
				Camera.main.rect = cameraRect;
				exploderCollider.radius = val * 15f;
			}).setEase(LeanTweenType.easeOutCubic)
				.setDelay(2f)
				.setOnComplete(DestroyExploder);
			LeanTween.value(Camera.main.gameObject, 0.13f, 0f, 1f).setOnUpdate(delegate(float val)
			{
				Camera.main.transform.position += new Vector3(0f, val, 0f);
			}).setEase(LeanTweenType.easeOutCubic)
				.setDelay(2f);
			LeanTween.value(base.gameObject, Time.timeScale, 0.4f, 0.35f).setOnUpdate(delegate(float val)
			{
				Time.timeScale = val;
			}).setEase(LeanTweenType.easeInOutCubic)
				.setRepeat(2)
				.setLoopPingPong()
				.setDelay(1.9f);
			LeanTween.value(mainlight.gameObject, mainlight.intensity, 1.1f, 0.12f).setOnUpdate(delegate(float val)
			{
				mainlight.intensity = val;
			}).setEase(LeanTweenType.easeOutCubic)
				.setOnComplete(ResetIntensity)
				.setDelay(2f);
			Invoke("EndAttack", 10f);
		}
	}

	private void DestroyExploder()
	{
		UnityEngine.Object.Destroy(exploderCollider);
	}

	private void ResetIntensity()
	{
		LeanTween.value(chargeParticles.gameObject, chargeParticles.startSpeed, 0.3f, 0.5f).setOnUpdate(delegate(float val)
		{
			chargeParticles.startSpeed = val;
		}).setEase(LeanTweenType.easeOutCubic);
		LeanTween.value(mainlight.gameObject, mainlight.intensity, defaultLightIntensity, 0.1f).setOnUpdate(delegate(float val)
		{
			mainlight.intensity = val;
		}).setEase(LeanTweenType.easeInOutCubic);
	}

	private void EndAttack()
	{
		UnityEngine.Object.Destroy(effect);
		StateManager.heightLimit = 3;
		StateManager.specialAttack = false;
		UnityEngine.Object.Destroy(base.gameObject);
	}
}
